package com.qw.soul.permission.callbcak;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import com.qw.soul.permission.PermissionActivityManager;
import com.qw.soul.permission.bean.Permission;
import com.qw.soul.permission.support.PermissionsPageManager;

/**
 * Created by ytf on 2019/07/17.
 * Description:
 */
public abstract class DefaultRefusedImpl implements CheckRequestPermissionsListener
{

    @Override
    public void onPermissionDenied(Permission[] refusedPermissions)
    {
        final Activity activity = PermissionActivityManager.getInstance().getTopActivity();
        if (null == activity)
        {
            return;
        }
        StringBuilder sb = new StringBuilder();
        for (Permission p : refusedPermissions)
        {
            sb.append(Permission.getPermissionNameDesc(p.permissionName)).append("、");
        }
        sb.delete(sb.length() - 1, sb.length());

        new AlertDialog.Builder(activity)
                .setTitle("提示")
                .setMessage(sb.toString() + "异常，请前往设置 -> 应用管理 -> 权限管理允许相关权限。")
                .setPositiveButton("去设置", new DialogInterface.OnClickListener()
                {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i)
                    {
                        //去设置页
                        PermissionsPageManager.jumpPermissionManager(activity);
                    }
                }).create().show();
    }
}
